<?php

/**
 * RecepcionEmails form.
 *
 * @package    form
 * @subpackage RecepcionEmails
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
 */
class RecepcionEmailsForm extends BaseRecepcionEmailsForm
{

  public function setup()
  {
     parent::setup();
  }

  public function configure()
  {
  
    //$custom_decorator = new sfWidgetFormSchemaFormatterDefList($this->getWidgetSchema());
    //$this->getWidgetSchema()->addFormFormatter('deflist', $custom_decorator);
    //$this->getWidgetSchema()->setFormFormatterName('deflist');
  
	unset($this->validatorSchema['emailvalid']);
    unset($this->widgetSchema['emailvalid']);
	
	unset($this->validatorSchema['enews']);
    unset($this->widgetSchema['enews']);
	
	$this->setWidget('casasvisitadas', new sfWidgetFormInputHidden());
	$this->user = sfContext::getInstance()->getUser();
	$this->setDefault('casasvisitadas', $this->user->getVisitedString());

	$this->setWidget('idioma', new sfWidgetFormInputHidden());
	$this->setWidget('ip', new sfWidgetFormInputHidden());
	$this->setDefault('ip', '');
	$this->setWidget('vivienda', new sfWidgetFormInputHidden());
	$this->setWidget('fechahorarecepcion', new sfWidgetFormInputHidden());
	$this->setWidget('datainici', new sfWidgetFormInputText());
	$this->setWidget('datafin', new sfWidgetFormInputText());
	//$this->setWidget('datainici', new sfWidgetFormDateJQueryUI(array("change_month" => true, "change_year" => true)));
	//$this->setWidget('datafin', new sfWidgetFormDateJQueryUI(array("change_month" => true, "change_year" => true)));

	$this->validatorSchema['email'] = new sfValidatorEmail(array(), array('required' => 'Vous devez renseigner une adresse email valide afin qu\'on puisse vous r&eacute;pondre.'), array('invalid' => 'Vous devez renseigner une adresse email de r&eacute;ponse valide.'));
	$this->validatorSchema['mensaje'] = new sfValidatorString(array(), array('required' => 'Renseignez svp un message afin qu\'on puisse vous r&eacute;pondre.'));
	
	$this->validatorSchema['datainici'] = new sfValidatorDate(array('required' => false));
	$this->validatorSchema['datafin'] = new sfValidatorDate(array('required' => false));
	
	
	$this->setDefault('fechahorarecepcion', date('Y-m-d h:i:s'));
	$this->setDefault('datainici', '');
	$this->setDefault('datafin', '');
	
	$this->widgetSchema->setLabel('email', 'Votre adresse email*');
	$this->widgetSchema->setLabel('datainici', 'Date d\'arriv&eacute;e');
	$this->widgetSchema->setLabel('datafin', 'Date de d&eacute;part');
	$this->widgetSchema->setLabel('mensaje', 'Message*');

	foreach( $this->getFormFieldSchema( ) as $name => $formField )
{
   if( $formField->getError( ) != "" )
   {
      print( $name . " : " . $formField->getError( ) . "\n" );
   }
}

	
	$this->validatorSchema->setPostValidator(
  new sfValidatorSchemaCompare('datainici', sfValidatorSchemaCompare::LESS_THAN_EQUAL, 'datafin',
    array('throw_global_error' => true),
    array('invalid' => 'La date d\'arriv&eacute;e ("%left_field%") doit etre anterieur a la date de depart ("%right_field%")')
  )
);
  }
}